home *** CD-ROM | disk | FTP | other *** search
- #!/usr/bin/perl5
- #
- # html.pl
- #
- # Copyright 1988-1996 Silicon Graphics, Inc.
- # All rights reserved.
- #
- # This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- # the contents of this file may not be disclosed to third parties, copied or
- # duplicated in any form, in whole or in part, without the prior written
- # permission of Silicon Graphics, Inc.
- #
- # RESTRICTED RIGHTS LEGEND:
- # Use, duplication or disclosure by the Government is subject to restrictions
- # as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- # and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- # successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- # rights reserved under the Copyright Laws of the United States.
- #
- # $Id: html.pl,v 1.1 1997/11/18 22:36:08 jrw Exp $
-
- require "/usr/OnRamp/lib/OnRamp.pm";
-
- $title = $ARGV[0];
- $root_dir = "$document_root/apps/majordomo/$title";
- $url_root = $ENV{'SERVER_URL'} . "/apps/majordomo/$title";
- $dummy = $root_dir . "/dummy";
- $num_file = "$root_dir/num";
- $subject_file = "$root_dir/subject.html";
- $author_file = "$root_dir/author.html";
- $date_file = "$root_dir/date.html";
-
- &get_previous;
- &get_letter;
- &make_new_file;
- &fix_last_file;
- &make_authors;
- &make_subjects;
- &make_dates;
-
- sub make_dates {
- if ($num == 0) {
- open(OUT, "> $date_file");
- print OUT "<title>$title by date</title>\n"
- . "<a href=\"date.html\">[date]</a>\n"
- . "<a href=\"subject.html\">[subj]</a>\n"
- . "<a href=\"author.html\">[auth]</a>\n"
- . "<h1>$title by date</h1>\n"
- . "<!-- DATE: $date-->\n";
- print OUT "<ul>\n";
- print OUT "<li><a href=$url>$subject</a> <i>$date</i>\n";
- print OUT "</ul>\n";
- } else {
- open(IN, "< $date_file");
- open(OUT, "> $dummy");
- while(<IN>) {
- if ($_ =~ /\<\/ul/) {
- print OUT "<li><a href=$url>$subject</a> <i>$date</i>\n";
- print OUT "</ul>\n";
- } else { print OUT $_; }
- }
- close(IN);
- close(OUT);
-
- rename($dummy, $date_file);
- }
- }
-
- sub make_subjects {
- if ($num == 0) {
- open(OUT, "> $subject_file");
- print OUT "<title>$title by subject</title>\n"
- . "<a href=\"date.html\">[date]</a>\n"
- . "<a href=\"subject.html\">[subj]</a>\n"
- . "<a href=\"author.html\">[auth]</a>\n"
- . "<h1>$title by subject</h1>\n"
- . "<!-- SUBJECT: $subject-->\n";
- print OUT "<b>$subject</b>\n<ul>\n";
- print OUT "<li><a href=$url>$author</a> <i>$date</i>\n";
- print OUT "</ul>\n";
- print OUT "<!-- LAST -->\n";
- close(OUT);
- } else {
- open(IN, "< $subject_file");
- open(OUT, "> $dummy");
- if ($subject =~ /^[rR]e: (.*)/) {
- $short_sub = $1;
- $not_done = 1;
- while(<IN>) {
- $line = $_;
- if ($not_done && $_ =~ /\<\!-- SUBJECT\: (.*)--/) {
- $nsub = $1; undef $short_nsub;
- if ($nsub =~ /^[rR]e: (.*)/) { $short_nsub = $1; }
- if ($short_sub eq $nsub || $short_sub eq $short_nsub) {
- &append_subject;
- $not_done = 0;
- } else { print OUT $line; }
- } elsif ($not_done && $_ =~ /\<\!-- LAST --\>/) {
- &new_subject;
- print OUT $line;
- } else { print OUT $line; }
- }
- } else {
- while(<IN>) {
- if ($_ =~ /\<\!-- LAST --\>/) {
- &new_subject;
- print OUT $_;
- } else { print OUT $_; }
- }
- }
- close(OUT);
- close(IN);
-
- rename($dummy, $subject_file);
- }
- }
-
- sub append_subject {
- print OUT $line;
- while(<IN>) {
- if ($_ =~ /\<\/ul/) {
- print OUT "<li><a href=$url>$author</a> <i>$date</i>\n"
- . "</ul>\n";
- return;
- } else { print OUT $_; }
- }
- }
-
- sub new_subject {
- print OUT "<!-- SUBJECT: $subject-->\n";
- print OUT "<b>$subject</b>\n<ul>\n";
- print OUT "<li><a href=$url>$author</a> <i>$date</i>\n";
- print OUT "</ul>\n";
- }
-
- sub make_authors {
- if ($num == 0) {
- open(OUT, "> $author_file");
- print OUT "<title>$title by author</title>\n"
- . "<a href=\"date.html\">[date]</a>\n"
- . "<a href=\"subject.html\">[subj]</a>\n"
- . "<a href=\"author.html\">[auth]</a>\n"
- . "<h1>$title by author</h1>\n<p>\n"
- . "<!-- AUTHOR: $author-->\n";
- print OUT "<b>$author</b>\n<ul>\n";
- print OUT "<li><a href=$url>$subject</a> <i>$date</i>\n";
- print OUT "</ul>\n";
- print OUT "<!-- LAST -->\n";
- close(OUT);
- } else {
- $author =~ /\s+(.*)$/;
- $last_author = $1;
- $not_done = 1;
- open(IN, "< $author_file");
- open(OUT, "> $dummy");
- while(<IN>) {
- $line = $_;
- if ($not_done && $_ =~ /\<\!-- AUTHOR\: (.*)--/) {
- $la = $1;
- if ($author eq $la) {
- &append;
- $not_done = 0;
- } else {
- $la =~ /\s+(.*)$/;
- $last = $1;
- if ($last_author gt $last) {
- print OUT $line;
- next;
- }
- &new_author;
- $not_done = 0;
- print OUT $line;
- }
- } elsif ($not_done && $_ =~ /\<\!-- LAST --\>/) {
- &new_author;
- print OUT $_;
- } else { print OUT $_; }
- }
- close(IN);
- close(OUT);
-
- rename($dummy, $author_file);
- }
- }
-
- sub new_author {
- print OUT "<!-- AUTHOR: $author-->\n";
- print OUT "<b>$author</b>\n<ul>\n";
- print OUT "<li><a href=$url>$subject</a> <i>$date</i>\n";
- print OUT "</ul>\n";
- }
-
- sub append {
- print OUT $line;
- while(<IN>) {
- if ($_ =~ /\<\/ul/) {
- print OUT "<li><a href=$url>$subject</a> <i>$date</i>\n"
- . "</ul>\n";
- return;
- } else { print OUT $_; }
- }
- }
-
- sub make_new_file {
- $body =~ s/</</g;
- $body =~ s/>/>/g;
- $body =~ s/(http\:\/\/[a-zA-Z0-9\_\/\-\.]+)/\<a href=$1\>$1\<\/a\>/g;
- $body =~ s/([a-zA-Z0-9\_\/\-\.]+\@[a-zA-Z0-9\_\/\-\.]+)/\<a href=\"mailto: $1\"\>$1\<\/a\>/g;
- if ($body =~ /\n\-\-\s+\n/) {
- @splt = split(/\n\-\-\s+\n/, $body);
- $splt[0] =~ s/\n/<br>\n/g;
- $splt[0] .= "<pre>";
- $body = join("<br>\n--\n", @splt);
- $body .= "</pre>";
- } else {
- $body =~ s/\n/<br>\n/g;
- }
-
- open(OUT, "> $file");
- print OUT "<!--\n"
- . "$date\n"
- . "$author\n"
- . "$email\n"
- . "$subject\n"
- . "-->\n";
- print OUT "<title>$title: $subject</title>\n"
- . "<a href=\"date.html\">[date]</a>\n"
- . "<a href=\"subject.html\">[subj]</a>\n"
- . "<a href=\"author.html\">[auth]</a>\n"
- . "<h1>$subject</h1>\n"
- . "$author (<i>$email</i>)<br>\n"
- . "<i>$date</i>\n<p>\n<ul>\n";
- if ($num > 0) {
- print OUT "<li><b>Last message: </b>"
- . "<a href=\"$last_url\">$last_author: $last_subject</a>\n";
- }
- print OUT "<!-- _NEXT_HERE_ -->\n";
- print OUT "</ul>\n"
- . "$body\n<p>\n<ul>\n";
- if ($num > 0) {
- print OUT "<li><b>Last message: </b>"
- . "<a href=\"$last_url\">$last_author: $last_subject</a>\n";
- }
- print OUT "<!-- _NEXT_HERE_ -->\n";
- print OUT "</ul>\n";
- close(OUT);
- }
-
- sub fix_last_file {
- open(IN, "< $last_file");
- open(OUT, "> $dummy");
- while(<IN>) {
- if ($_ =~ /_NEXT_HERE_/) {
- print OUT "<li><b>Next message: </b>"
- . "<a href=\"$url\">$author: $subject</a>\n";
- } else { print OUT $_; }
- }
- close(IN);
- close(OUT);
-
- rename($dummy, $last_file);
- }
-
- sub get_previous {
- if (-e $num_file) {
- open(IN, "< $num_file");
- $num = <IN>;
- close(IN);
-
- for ($i=4; $i>length($num); $i--) { $f_num .= "0"; }
- $f_num .= $num;
- $file = "$root_dir/$f_num\.html";
-
- $last_num = $num-1;
- for ($i=4; $i>length($last_num); $i--) { $f_lnum .= "0"; }
- $f_lnum .= $last_num;
- $last_file = "$root_dir/$f_lnum\.html";
-
- open(IN, "< $last_file");
- $last_date = <IN>;
- $last_date = <IN>;
- $last_author = <IN>;
- $last_email = <IN>;
- $last_subject = <IN>;
- close(IN);
-
- $url = $url_root . "/" . $f_num . ".html";
- $last_url = $url_root . "/" . $f_lnum . ".html";
- } else {
- $num = 0;
- $f_num = "0000";
- $file = $root_dir . "/0000.html";
- $url = $url_root . "/" . $f_num . ".html";
- if (! -d $root_dir) { mkdir($root_dir, 0755); }
- }
- open(OUT, "> $num_file");
- print OUT $num + 1;
- close(OUT);
- }
-
- sub get_letter {
- while(<STDIN>) {
- $need_subj = 1; $need_name = 1; $need_date = 1;
- if ($need_name && $_ =~ /^From:\s+(.*)/)
- { &get_from($1); $need_name = 0; }
- elsif ($need_date && $_ =~ /^Date:\s+(.*)/)
- { $date = $1; $need_date = 0; }
- elsif ($need_subj && $_ =~ /^Subject:\s+(.*)/)
- { $subject = $1; $need_subj = 0; }
- elsif ($_ eq "\n") {
- $save = $/; undef $/;
- $body = <STDIN>;
- $/ = $save;
- }
- if ($subject eq "") { $subject = "[no subject]"; }
- }
- }
-
- sub get_from {
- if ($_[0] =~ /(.*)\s+\<(.*)\>/) {
- $author = $1; $email = $2;
- if ($author =~ /\"(.*)\"/) { $author = $1; }
- } elsif ($_[0] =~ /(.*)\s+\((.*)\)/) {
- $email = $1;
- $author = $2;
- } else {
- $author = "name format error";
- $email = "email format error";
- }
- }
-